package ext.opensource.netty.common;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class LogDispatchHandler extends ChannelInboundHandlerAdapter {

	@Override
	public void channelRegistered(final ChannelHandlerContext ctx) throws Exception {
		NettyLog.info(String.format("Registered id:%s", ctx.channel().id().asLongText()));
		super.channelRegistered(ctx);
	}

	@Override
	public void channelUnregistered(final ChannelHandlerContext ctx) throws Exception {
		NettyLog.info(String.format("UnRegistered id:%s", ctx.channel().id().asLongText()));
		super.channelUnregistered(ctx);
	}

	@Override
	public void channelActive(final ChannelHandlerContext ctx) throws Exception {
		NettyLog.info(String.format("Active id:%s", ctx.channel().id().asLongText()));
		super.channelActive(ctx);
	}

	@Override
	public void channelInactive(final ChannelHandlerContext ctx) throws Exception {
		NettyLog.info(String.format("Inactive id:%s", ctx.channel().id().asLongText()));
		super.channelInactive(ctx);
	}

	@Override
	public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
		NettyLog.info(String.format("Read id:%s", ctx.channel().id().asLongText()));
		super.channelRead(ctx, msg);
	}

	@Override
	public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception {
		NettyLog.info(String.format("exceptionCaught id:%s", ctx.channel().id().asLongText()));
		super.exceptionCaught(ctx, cause);
	}
}
